[

	$navbarout = string;

	if($navbarout->size == 0);

		var('get1' = (xs_cat->(subTreeSQL(-id=1, -cattable='Pages',-depth=1,-relative=true,-xtraReturn=', node.navorder, node.page_url',-xtraWhere=' '))));
		inline($connection_db, -sql=($get1));
$navbarout += '<ul class="nav">';
				
				if($show_home_in_navbar);
						$navbarout += '<li><a href="/Home">Home</a></li>';
				/if;
				
				
				rows;
						var('name' = column('name'));
						var('url' = column('page_url'));
						var('nodeID' = column('id'));
						
						var('path_to_node' = (xs_cat->getURLpath(-id=$nodeID, -cattable='Pages')));
						!$path_to_node->beginswith('/') ? ($path_to_node = ('/' $path_to_node));
						!$path_to_node->endswith('/') ? ($path_to_node = ($path_to_node '/'));
						//$admin_toolbar += '<pre>Node ID: '+$nodeID ', '+$path_to_node '</pre>';
$navbarout += '
	<li>
		<a href="'+$path_to_node '">'+$name '</a>
		';
								var('get1' = (xs_cat->(subTreeSQL(-id=$nodeID, -cattable='Pages',-depth=1,-relative=true,-xtraReturn=', node.navorder, node.page_url',-xtraWhere=' AND node.visible_in_menu = 1'))));
								inline($connection_db, -sql=($get1));
										if(found_count > 0);
$navbarout += '<ul>
		';
												rows;
														var('name' = column('name'));
														var('nodeid'=column('id'));
														var('path_to_node' = (xs_cat->getURLpath(-id=column('id'), -cattable='Pages')));
														!$path_to_node->beginswith('/') ? $path_to_node = '/' $path_to_node;
														!$path_to_node->endswith('/') ? ($path_to_node = ($path_to_node '/'));
														//$admin_toolbar += '<pre>Node ID: '+$nodeID ', '+$path_to_node '</pre>';
														$navbarout += '
					<li'+(loop_count == found_count ? ' class="last" ') '>
														';
														
																$navbarout += '
						<a href="'+$path_to_node '" >
																';
																
								$navbarout += $name;
																
																
																var('get2' = (xs_cat->(subTreeSQL(-id=$nodeID, -cattable='Pages',-depth=1,-relative=true,-xtraReturn=', node.navorder, node.page_url',-xtraWhere=' AND node.visible_in_menu = 1'))));
																var('showchildren'=false);
																inline(-inlinename=('subs_'$nodeid), $connection_db, -sql=($get2));
																		if(found_count > 0);
																				$navbarout += ' >';
																				$showchildren = true;
																		/if;
																/inline;
																
																
																


																
																$navbarout += '
						</a>
																				';
																
																if($showchildren);
																		rows(-inlinename=(('subs_'$nodeid)));
																				var('name' = column('name'));
																				var('nodeid'=column('id'));
																				var('path_to_node' = (xs_cat->getURLpath(-id=column('id'), -cattable='Pages')));
																				!$path_to_node->beginswith('/') ? ($path_to_node = ('/' $path_to_node));
																				!$path_to_node->endswith('/') ? ($path_to_node = ($path_to_node '/'));
																				loop_count == 1 ? $navbarout += '
						<ul
																				>';
																				
																				
																				$navbarout += '
							<li '+(loop_count == found_count ? ' class="last" ') '>
																				';
																				
																						$navbarout += '
								<a href="'+$path_to_node '">
																						';
																						
									$navbarout += $name;
																								
																						$navbarout += '
								</a>
																						';
																				
																				$navbarout += '
							</li>
																				';
																				
																				loop_count == found_count ? $navbarout += '
						</ul>
																				';
																		/rows;
																/if;
																
																
															
														
														$navbarout += '
					</li>
														';
												/rows;
												$navbarout +=  '
				</ul>
												';
										/if;
								/inline;
								
						$navbarout += '</li>';
				/rows;
				
						//'<li id="contact"><a href="/Contact">Contact</a></li>';
				$navbarout += '</ul>';
		/inline;
		
		$navbarout;
	
	else;
		$navbarout;
	/if;
	
]

